/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;

/**
 * <p>Project: mybatis2021 - DruidConfig
 * <p>Powered by webrx On 2021-07-19 10:52:43
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 15
 */
@Configuration
@PropertySource("classpath:db.properties")
public class DruidConfig {
    @Autowired
    Environment env;

    @Value("${db.url}")
    private String jdbcurl;
    @Value("${db.driver}")
    private String driver;
    @Value("${db.username}")
    private String username;
    @Value("${db.password}")
    private String password;

    @Bean("ds")
    public DataSource dataSource(@Value("${db.url}") String u) {
        System.out.println(env.getProperty("db.url"));
        System.out.println(this.jdbcurl);
        System.out.println(u);

        DruidDataSource ds = new DruidDataSource();
        ds.setUrl(jdbcurl);
        ds.setUsername(username);
        ds.setPassword(password);
        ds.setDriverClassName(driver);
        return ds;
    }
}
